using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CollapsableBox : System.Web.UI.UserControl
{

    private bool collapsed;
    private string collapseButtonImageUrl = "~/App_Themes/default/images/icons/16/chevron_drk_up_16.gif";
    private string expandButtonImageUrl = "~/App_Themes/default/images/icons/16/chevron_drk_down_16.gif";
    private string title = "Undefined";

    public bool IsCollapsed
    {
        get 
        {
            if (ViewState["test"] == null)
            {
                ViewState["test"] = !BoxContent.Visible;
            }

            return (bool)ViewState["test"];
        }
        set
        {
            ViewState["test"] = value;
        }
    }

    public string CollapseButtonImageUrl
    {
        get { return this.collapseButtonImageUrl; }
        set { this.collapseButtonImageUrl = value; }
    }

    public string ExpandButtonImageUrl
    {
        get { return this.expandButtonImageUrl; }
        set { this.expandButtonImageUrl = value; }
    }

    public string Title
    {
        get { return this.title; }
        set { this.title = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        this.TitleLiteral.Text = Title;

        this.BoxContent.Controls.Add(new Calendar());

        this.CollapseExpandButton.Click += new ImageClickEventHandler(CollapseExpandButton_Click);
        this.CollapseExpandButton.ImageUrl = (IsCollapsed) ? expandButtonImageUrl : collapseButtonImageUrl;
        this.BoxContent.Visible = !IsCollapsed;

    }


    protected void CollapseExpandButton_Click(object sender, ImageClickEventArgs e)
    {

        IsCollapsed = !IsCollapsed;
        this.CollapseExpandButton.ImageUrl = (IsCollapsed) ? expandButtonImageUrl : collapseButtonImageUrl;
        this.BoxContent.Visible = !IsCollapsed;

    }
}
